package org.xiaov.lunasql.spring.proxy;

import lombok.Getter;

import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

/**
 * The type Abstract data source proxy.
 *
 * @author xiaovcloud
 * @since 2024/1/23 10:50
 */
@Getter
public abstract class AbstractDataSourceProxy implements DataSource {

	/**
	 * The Target data source.
	 */
	protected DataSource targetDataSource;

	/**
	 * Instantiates a new Abstract data source proxy.
	 */
	public AbstractDataSourceProxy() {
	}

	/**
	 * Instantiates a new Abstract data source proxy.
	 *
	 * @param targetDataSource the target data source
	 */
	public AbstractDataSourceProxy(DataSource targetDataSource) {
		this.targetDataSource = targetDataSource;
	}


	@Override
	public <T> T unwrap(Class<T> iface) throws SQLException {
		return targetDataSource.unwrap(iface);
	}

	@Override
	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		return targetDataSource.isWrapperFor(iface);
	}

	@Override
	public PrintWriter getLogWriter() throws SQLException {
		return targetDataSource.getLogWriter();
	}

	@Override
	public void setLogWriter(PrintWriter out) throws SQLException {
		targetDataSource.setLogWriter(out);
	}

	@Override
	public int getLoginTimeout() throws SQLException {
		return targetDataSource.getLoginTimeout();
	}

	@Override
	public void setLoginTimeout(int seconds) throws SQLException {
		targetDataSource.setLoginTimeout(seconds);
	}

	@Override
	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
		return targetDataSource.getParentLogger();
	}
}
